package com.java110.common.api;

import com.alibaba.fastjson.JSONObject;
import com.java110.common.bmo.appraise.IGetAppraiseBMO;
import com.java110.common.bmo.appraise.ISaveAppraiseBMO;
import com.java110.dto.appraise.AppraiseDto;
import com.java110.po.appraise.AppraisePo;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/appraise")
public class AppraiseApi {
    @Autowired
    private ISaveAppraiseBMO saveAppraiseBMOImpl;

    @Autowired
    private IGetAppraiseBMO getAppraiseBMOImpl;

    /**
     *
     * @ServiceCode /appraise/saveAppraise
     * @return
     */
    @RequestMapping(value = "/saveAppraise", method = RequestMethod.POST)
    public ResponseEntity<String> saveAppraise(@RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "appraiseScore", "请求报文中未包含appraiseScore");
        Assert.hasKeyAndValue(reqJson, "appraiseType", "请求报文中未包含appraiseType");//评论类型 默认10000 普通类型
        Assert.hasKeyAndValue(reqJson, "objType", "请求报文中未包含objType");//评论对象类型 10001对维修单评价 10002对人评价 10003对物业公司
        Assert.hasKeyAndValue(reqJson, "objId", "请求报文中未包含objId");//评论对象id
        Assert.hasKeyAndValue(reqJson, "appraiseUserId", "请求报文中未包含appraiseUserId");//评价人
        AppraisePo appraisePo = BeanConvertUtil.covertBean(reqJson, AppraisePo.class);
        return saveAppraiseBMOImpl.saveAppraise(appraisePo);
    }

    /**
     *
     * @ServiceCode  /appraise/getAppraise
     * @return
     */
    @RequestMapping(value = "/getAppraise", method = RequestMethod.GET)
    public ResponseEntity<String> getAppraise(@RequestParam(value = "appraiseId", required = false) String appraiseId,
                                              @RequestParam(value = "objType", required = false) String objType,
                                              @RequestParam(value = "objId", required = false) String objId,
                                              @RequestParam(value = "appraiseUserId", required = false) String appraiseUserId,
                                              @RequestParam(value = "page") int page,
                                              @RequestParam(value = "row") int row
    ) {
        AppraiseDto appraiseDto = new AppraiseDto();
        appraiseDto.setAppraiseId(appraiseId);
        appraiseDto.setObjType(objType);
        appraiseDto.setObjId(objId);
        appraiseDto.setAppraiseUserId(appraiseUserId);
        appraiseDto.setRow(row);
        appraiseDto.setPage(page);
        return getAppraiseBMOImpl.getAppraise(appraiseDto);
    }
}
